// Note that the palyers may actually reach higher than the maximum scores

#include <iostream>
#include <map>

using namespace std;

string name[1000];
int score[1000];
map<string, int> m, m1;
int n;

int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		cin >> name[i] >> score[i];

		if (m.find(name[i]) == m.end()) m[name[i]] = score[i];
		else m[name[i]] += score[i];		
	}

	int maximum = -1000000000;
	for (int i = 0; i < n; i++) 
		if (m[name[i]] > maximum) maximum = m[name[i]];

	string result;
	for (int i = 0; i < n; i++) 
	{
		if (m1.find(name[i]) == m1.end()) m1[name[i]] = score[i];
		else m1[name[i]] += score[i];

		if (m1[name[i]] >= maximum && m[name[i]] == maximum)
		{
			cout << name[i] << endl;
			break;
		}
	}
	
	return 0;
}
